const { mongoose, db } = require("../utils/mongoose");

let schema = mongoose.Schema({
  desc:{type:String,required:false},
  author:{type:String,required:false},
  date:{type:String,require:false}
});

let Collection = mongoose.model("quotes", schema);

//新增
const add = (data) => {
  let model = new Collection(data);
  return model
    .save()
    .then((res) => res)
    .catch((err) => {
      return false;
    });
};
//查询
const find = (payload) => {
  return Collection.find(payload)
    .then((res) => res)
    .catch((err) => {
      console.log(err);
      return false;
    });
};
//操作
const update = (query, updated) => {
  return Collection.updateOne(query, updated)
    .then((res) => res)
    .catch((err) => {
      console.log(err);
      return false;
    });
};
module.exports = {
  find,
  add,
  update,
};
